package com.example.smart_city_0829.activity.lawyer_consultation.fragment;

import android.graphics.Canvas;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smart_city_0829.R;
import com.example.smart_city_0829.base.BaseFragment;
import com.example.smart_city_0829.entity.lawyer_onsultation.LawyerList;
import com.example.smart_city_0829.utils.Constant;
import com.google.gson.reflect.TypeToken;

import java.util.Calendar;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link LawyerInfoFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class LawyerInfoFragment extends BaseFragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public LawyerInfoFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment LawyerInfoFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static LawyerInfoFragment newInstance(String param1, String param2) {
        LawyerInfoFragment fragment = new LawyerInfoFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    private ImageView imageView;
    private TextView baseInfo;
    private TextView eduInfo;
    private TextView tag1;
    private TextView tag2;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_lawyer_info;
    }

    @Override
    protected void initView() {
        imageView = (ImageView) rootView.findViewById(R.id.imageView);
        baseInfo = (TextView) rootView.findViewById(R.id.baseInfo);
        eduInfo = (TextView) rootView.findViewById(R.id.eduInfo);
        tag1 = (TextView) rootView.findViewById(R.id.tag1);
        tag2 = (TextView) rootView.findViewById(R.id.tag2);
    }

    @Override
    protected void initData() {
        final LawyerList.RowsBean lawyer = gson.fromJson(mParam1, new TypeToken<LawyerList.RowsBean>() {}.getType());

        Glide.with(requireActivity())
                .load(Constant.BASE_URL + lawyer.getCertificateImgUrl())
                .into(imageView);

        baseInfo.setText(lawyer.getBaseInfo());
        eduInfo.setText("教育经历："+lawyer.getEduInfo());
        tag1.setText("已从业"+(Calendar.getInstance().get(Calendar.YEAR) - Integer.parseInt(lawyer.getWorkStartAt().substring(0,4)))+"年");
        tag2.setText("职业证号："+lawyer.getLicenseNo());

    }

    @Override
    protected void initEvent() {

    }
}